<?php

namespace App\Console\Commands;

use App\Http\Services\ApiServices;
use App\Lib\Search;
use Carbon\Carbon;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Redis;

class CommandCreateEsIndex extends Command
{
    protected $signature = 'CreatedEsIndex';
    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '创建Es索引';

     /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $indexArr = [
            'chat_friend_anchor_user',//交友es
            'chat_friend_user',//交友es
            'kk_user',//用户信息
            'kk_room_none',//房间
            'kk_room_bussiness',//公会房间
            'kk_music',//音乐
            'kk_room_hot',//推荐房间
        ];

        //更新es
        $search = new Search();
        foreach($indexArr as $v){

            // $search->deleteAllIndex($v);
            // echo '删除ES索引成功-|'.$v." | \r\n";
	    $checkIdex = $search->checkIndexExists($v);
            if(!$checkIdex){
                $params = ['index'=>$v];
                $res = $search->createIndex($params);
                echo '创建ES索引成功-|'.$v." | \r\n";
            }
        }

    }
}
